select 
  'g' as transfer_category,
    s1.source,
    s2.source as source_pair,
    s1.stop_id as from_stop_id,
    s2.stop_id as to_stop_id,
    v1.parent_station as from_stop_idu,
    v2.parent_station as to_stop_idu,
    s1.source || '_' || v1.parent_station as from_stop_sidu,
    s2.source || '_' || v2.parent_station as to_stop_sidu,
    0 as transfer_type,
    null as min_transfer_time,
    6371.0 * acos(
      sin(90.0 - s1.stop_lat * pi() / 180.0) *
      sin(90.0 - s2.stop_lat * pi() / 180.0) *
      cos(
        (s1.stop_lon * pi() / 180.0) -
        (s2.stop_lon * pi() / 180.0)
      ) +
      cos(90.0 - s1.stop_lat * pi() / 180.0) *
      cos(90.0 - s2.stop_lat * pi() / 180.0)
    ) as dist_km
from _cvstopparent v1
  join _cvstopparent v2 on v1.source = v2.source or v1.source < v2.source
  join stops s1 on s1.stop_id = v1.stop_id and s1.source = v1.source
  join stops s2 on s2.stop_id = v2.stop_id and s2.source = v2.source
  where v1.stop_id = v1.parent_station 
  and v2.stop_id = v2.parent_station
  and dist_km is not null and dist_km < 5
